<?php
namespace Admin\Controller;
use Think\Controller;
class indexController extends CommonController {



    public function index(){

        $this->display();
    }

    public function welcome()
    {	
    	if (S('welcomedata')) {
    		$data = S('welcomedata');
    	}else{
    		$data = $this->conutdata();
    		S('welcomedata',$data,600);
    	}
    	
		$this->assign('data',$data);

    	$this->display();
    }

    public function getcity()
    {
    	$data= array();
		$sql = "select count(id) num from user where shen like '北京%'";
		$sql .=" UNION all select count(id) num from user where shen like '天津%'";
		$sql .=" UNION all select count(id) num from user where shen like '上海%'";
		$sql .=" UNION all select count(id) num from user where shen like '重庆%'";
		$sql .=" UNION all select count(id) num from user where shen like '河北%'";
		$sql .=" UNION all select count(id) num from user where shen like '河南%'";
		$sql .=" UNION all select count(id) num from user where shen like '云南%'";
		$sql .=" UNION all select count(id) num from user where shen like '辽宁%'";
		$sql .=" UNION all select count(id) num from user where shen like '黑龙江%'";
		$sql .=" UNION all select count(id) num from user where shen like '湖南%'";
		$sql .=" UNION all select count(id) num from user where shen like '安徽%'";
		$sql .=" UNION all select count(id) num from user where shen like '山东%'";
		$sql .=" UNION all select count(id) num from user where shen like '新疆%'";
		$sql .=" UNION all select count(id) num from user where shen like '江苏%'";
		$sql .=" UNION all select count(id) num from user where shen like '浙江%'";
		$sql .=" UNION all select count(id) num from user where shen like '江西%'";
		$sql .=" UNION all select count(id) num from user where shen like '湖北%'";
		$sql .=" UNION all select count(id) num from user where shen like '广西%'";
		$sql .=" UNION all select count(id) num from user where shen like '甘肃%'";
		$sql .=" UNION all select count(id) num from user where shen like '山西%'";
		$sql .=" UNION all select count(id) num from user where shen like '内蒙古%'";
		$sql .=" UNION all select count(id) num from user where shen like '陕西%'";
		$sql .=" UNION all select count(id) num from user where shen like '吉林%'";
		$sql .=" UNION all select count(id) num from user where shen like '福建%'";
		$sql .=" UNION all select count(id) num from user where shen like '贵州%'";
		$sql .=" UNION all select count(id) num from user where shen like '广东%'";
		$sql .=" UNION all select count(id) num from user where shen like '青海%'";
		$sql .=" UNION all select count(id) num from user where shen like '西藏%'";
		$sql .=" UNION all select count(id) num from user where shen like '四川%'";
		$sql .=" UNION all select count(id) num from user where shen like '宁夏%'";
		$sql .=" UNION all select count(id) num from user where shen like '海南%'";
		$sql .=" UNION all select count(id) num from user where shen like '台湾%'";
		$sql .=" UNION all select count(id) num from user where shen like '香港%'";
		$sql .=" UNION all select count(id) num from user where shen like '澳门%'";
    	
		$data= array();
		$res=M('user')->query($sql);
    	$data[]=array(
    		'name'=>'北京',
    		'value'=>$res[0]['num'],
    		);
    	$data[]=array(
    		'name'=>'天津',
    		'value'=>$res[1]['num'],
    		);
    	$data[]=array(
    		'name'=>'上海',
    		'value'=>$res[2]['num'],
    		);
    	$data[]=array(
    		'name'=>'重庆',
    		'value'=>$res[3]['num'],
    		);
    	$data[]=array(
    		'name'=>'河北',
    		'value'=>$res[4]['num'],
    		);
    	$data[]=array(
    		'name'=>'河南',
    		'value'=>$res[5]['num'],
    		);
    	$data[]=array(
    		'name'=>'云南',
    		'value'=>$res[6]['num'],
    		);
    	$data[]=array(
    		'name'=>'辽宁',
    		'value'=>$res[7]['num'],
    		);
    	$data[]=array(
    		'name'=>'黑龙江',
    		'value'=>$res[8]['num'],
    		);
    	$data[]=array(
    		'name'=>'湖南',
    		'value'=>$res[9]['num'],
    		);
    	$data[]=array(
    		'name'=>'安徽',
    		'value'=>$res[10]['num'],
    		);
    	$data[]=array(
    		'name'=>'山东',
    		'value'=>$res[11]['num'],
    		);
    	$data[]=array(
    		'name'=>'新疆',
    		'value'=>$res[12]['num'],
    		);
    	$data[]=array(
    		'name'=>'江苏',
    		'value'=>$res[13]['num'],
    		);
    	$data[]=array(
    		'name'=>'浙江',
    		'value'=>$res[14]['num'],
    		);
    	$data[]=array(
    		'name'=>'江西',
    		'value'=>$res[15]['num'],
    		);
    	$data[]=array(
    		'name'=>'湖北',
    		'value'=>$res[16]['num'],
    		);
    	$data[]=array(
    		'name'=>'广西',
    		'value'=>$res[17]['num'],
    		);
    	$data[]=array(
    		'name'=>'甘肃',
    		'value'=>$res[18]['num'],
    		);
    	$data[]=array(
    		'name'=>'山西',
    		'value'=>$res[19]['num'],
    		);
    	$data[]=array(
    		'name'=>'内蒙古',
    		'value'=>$res[20]['num'],
    		);
    	$data[]=array(
    		'name'=>'陕西',
    		'value'=>$res[21]['num'],
    		);
    	$data[]=array(
    		'name'=>'吉林',
    		'value'=>$res[22]['num'],
    		);
    	$data[]=array(
    		'name'=>'福建',
    		'value'=>$res[23]['num'],
    		);
    	$data[]=array(
    		'name'=>'贵州',
    		'value'=>$res[24]['num'],
    		);
    	$data[]=array(
    		'name'=>'广东',
    		'value'=>$res[25]['num'],
    		);
    	$data[]=array(
    		'name'=>'青海',
    		'value'=>$res[26]['num'],
    		);
    	$data[]=array(
    		'name'=>'西藏',
    		'value'=>$res[27]['num'],
    		);
    	$data[]=array(
    		'name'=>'四川',
    		'value'=>$res[28]['num'],
    		);
    	$data[]=array(
    		'name'=>'宁夏',
    		'value'=>$res[29]['num'],
    		);
    	$data[]=array(
    		'name'=>'海南',
    		'value'=>$res[30]['num'],
    		);
    	$data[]=array(
    		'name'=>'台湾',
    		'value'=>$res[31]['num'],
    		);
    	$data[]=array(
    		'name'=>'香港',
    		'value'=>$res[32]['num'],
    		);
    	$data[]=array(
    		'name'=>'澳门',
    		'value'=>$res[33]['num'],
    		);


    	echo json_encode($data);

    }

    public function welcomenull()
    {
    	S('welcomedata',null);

    }

    public function conutdata()
    {
    	
    	$time=date('y-m-d');
    	$time=strtotime($time);
    	$yesterday=strtotime('-1 days',$time);
    	$week=strtotime('-7 days',$time);
    	$mooth=strtotime('-30 days',$time);
    	$data = array();
    	//问题总数
    	$sql="select count(id) cn from question";
    	$res=M()->query($sql);
		$data['总数'][]=M()->query($sql)[0]['cn'];
		//回答总数
		$sql="select count(id) cn from answer";
    	$res=M()->query($sql);
		$data['总数'][]=M()->query($sql)[0]['cn'];
		//用户总数
		$sql="select count(id) cn from user";
    	$res=M()->query($sql);
		$data['总数'][]=M()->query($sql)[0]['cn'];
		//今天问题
    	$sql="select count(id) cn from question where create_time>'{$time}'";
    	$res=M()->query($sql);
		$data['今天'][]=M()->query($sql)[0]['cn'];
		//今天回复
		$sql="select count(id) cn from answer where create_time>'{$time}'";
    	$res=M()->query($sql);
		$data['今天'][]=M()->query($sql)[0]['cn'];
		//今天用户
		$sql="select count(id) cn from user where create_time>'{$time}'";
    	$res=M()->query($sql);
		$data['今天'][]=M()->query($sql)[0]['cn'];
		//昨天问题
    	$sql="select count(id) cn from question where create_time>'{$yesterday}' and create_time<'{$time}'";
    	$res=M()->query($sql);
		$data['昨天'][]=M()->query($sql)[0]['cn'];
		//昨天回复
		$sql="select count(id) cn from answer where create_time>'{$yesterday}' and create_time<'{$time}'";
    	$res=M()->query($sql);
		$data['昨天'][]=M()->query($sql)[0]['cn'];
		//昨天用户
		$sql="select count(id) cn from user where create_time>'{$yesterday}' and create_time<'{$time}'";
    	$res=M()->query($sql);
		$data['昨天'][]=M()->query($sql)[0]['cn'];
		//本周问题
		$sql="select count(id) cn from question where create_time>'{$week}'";
		$res=M()->query($sql);
		$data['本周'][]=M()->query($sql)[0]['cn'];
		//本周回复
		$sql="select count(id) cn from answer where create_time>'{$week}'";
		$res=M()->query($sql);
		$data['本周'][]=M()->query($sql)[0]['cn'];
		//本周用户
		$sql="select count(id) cn from user where create_time>'{$week}'";
		$res=M()->query($sql);
		$data['本周'][]=M()->query($sql)[0]['cn'];
		//本月问题
		$sql="select count(id) cn from question where create_time>'{$mooth}'";
		$res=M()->query($sql);
		$data['本月'][]=M()->query($sql)[0]['cn'];
		//本月回复
		$sql="select count(id) cn from answer where create_time>'{$mooth}'";
		$res=M()->query($sql);
		$data['本月'][]=M()->query($sql)[0]['cn'];
		//本月用户
		$sql="select count(id) cn from user where create_time>'{$mooth}'";
		$res=M()->query($sql);
		$data['本月'][]=M()->query($sql)[0]['cn'];

		return $data;
    }



}